<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>{$title} - 【66Play】一键记录你的游戏青春</title>
    <link rel="stylesheet" href="__PUBLIC__/Home/static/css/nickname.css"/>
    <script type="text/javascript">
        {:C('GLOBAL_BDHM')}
    </script>
</head>
<body>
        <div class="head">
            <div class="logo">
                <img src="__PUBLIC__/Home/static/images/logo.png">
            </div>
        </div>
        <div class="login">
            <div class="login-info">
                <div class="avatar">
                    <img src="{$sso_avatar|default="__PUBLIC__/Home/static/temp_img/avatar.png"}" alt=""/>
                </div>
                <div class="nickname1">尊敬的{$sso_nickname|default="用户"}</div>
            </div>
            <div class="input-login">
                <div class="input-box">
                    <div class="tips">您是否使用{$sso_channel}昵称登录？</div>
                    <div class="input input-nickname">
                        <i></i>
                        <input type="text" value="{$sso_nickname}" class="nickname" onkeyup="test()"/>
                    </div>
                    <div class="msg"></div>
                    <div class="login-btn">
                        <button onclick="submit()">确认</button>
                    </div>
                </div>
            </div>
        </div>
        <include file="common/footer" />
</body>
<script src="__PUBLIC__/Home/static/js/jquery-1.8.2.min.js"></script>
<script>
    function test(){
        $(".input span").remove();
        var nickname = $(".nickname").val();
        var myreg =/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;
        var s=myreg.test(nickname);
        if(s){
            $(".input").append("<span class='wrong'></span>");
            $(".msg").html("昵称不合法，请不要输入特殊字符！");
        }else{
            $(".input").append("<span class='right'></span>");
            $(".msg").empty();
            $.ajax({
                url:"__ROOT__/api/visitor/checkNickname?nickname="+nickname+"",
                type:'get',
                dataType:'json',
                success:function(data){
                    $(".input span").remove();
                    if(data.code==200){
                        $(".input").append("<span class='right'></span>");
                    }else{
                        $(".input").append("<span class='wrong'></span>");
                    }
                    $(".msg").html(data.info);
                }
            });
        }
    }

    function submit(){
        var redirect_url = '{$redirect_url}' || '/';
        $.ajax({
            url:'{:U('')}',
            data:{nickname:$(".nickname").val()},
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.state < 0){
                    alert(data.info)
                    return;
                }else{
                    window.location.href= redirect_url;
                }
            }
        });
    }
</script>
</html>